﻿using HtmlAgilityPack;
using Ozner.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ozner.BLL
{
    public class BaseModelBLL:BaseBLL
    {
        //对于在TabMain中的页面设置路径
        public string URL { get; set; }
        //对于在TabMain中的页面保存HtmlDocument
        private HtmlDocument Document = null;
        //对于在TabMain中显示的窗口查询当前位置
        #region 查询当前位置
        public BaseResult<List<string>> GetCurrentLocation()
        {
            BaseResult<List<string>> br = GetLoginedDocument<List<string>>(URL);

            try
            {
                br.Object = new List<string>();
                if (br.Code == Code.OK)
                {
                    Document = br.OtherInfo as HtmlDocument;
                    //获取当前位置
                    HtmlNode hnFirst = Document.DocumentNode.SelectSingleNode("//div[@id='Panel-Receive']/div[@id='panel-header']/div[1]/div[1]");
                    HtmlNode hnSecond = Document.DocumentNode.SelectSingleNode("//div[@id='Panel-Receive']/div[@id='panel-header']/div[1]/span[1]");
                    if (hnFirst != null)
                    {
                        br.Object.Add(hnFirst.InnerText.Replace("&nbsp;", ""));
                    }
                    if (hnSecond != null)
                    {
                        br.Object.Add(hnSecond.InnerText.Replace("&nbsp;", ""));
                    }
                }
            }catch(Exception e)
            {
                Console.WriteLine(e.Message+"\n"+e.StackTrace);
            }
            return br;
        }
        #endregion
    }
}
